package test;

import java.util.*;

class PersonSortable implements Comparable<PersonSortable>{
	private String name;
	private int age;

	public PersonSortable(String name,int age){
		this.name=name;
		this.age=age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	@Override
	public String toString() {
		return name + "-" + age ;
	}

	@Override
	public int compareTo(PersonSortable o) {
		int x=this.name.compareTo(o.name);
		if (x!=0) 
			return x;
		else if(this.age > o.age)
			return  1;
		else if(this.age < o.age)
			return  -1;
		return 0;
	}

}
public class Main0401 {
	public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        while(in.hasNext()){
        ArrayList<PersonSortable> personSortable = new ArrayList<PersonSortable>();
        for(int i=0;i<n;i++){
        	personSortable.add(new PersonSortable(in.next(),in.nextInt()));
        }
        Collections.sort(personSortable);
        for(PersonSortable person1:personSortable){
        	System.out.println(person1);
        }
        System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));
        }
	}
}

